package leetcode.slidwidow;

public class Lc1493 {

    public int longestSubarray(int[] nums) {
        int ans = 0, i = 0, j = 0;
        int zeroCnt = 0;
        for (; j < nums.length; j++) {
            if (nums[j] == 1) continue;
            ans = Math.max(ans, j - i - 1);
            zeroCnt++;
            while (zeroCnt > 1) {
                if (nums[i] == 0) zeroCnt--;
                i++;
            }
        }
        ans = Math.max(ans, j - i - 1);
        return ans;
    }

    public static void main(String[] args) {
        Lc1493 lc1493 = new Lc1493();
        System.out.println(lc1493.longestSubarray(new int[]{1, 1, 1}));
    }


}
